<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/2/28
 * Time: 17:33
 * Mail:87658989@qq.com
 */

namespace app\cron\model;

use think\Exception;
use \think\Model;

class Order extends Model
{
    /**
     * 获取待派车订单
     * @param int $order_state 订单状态
     * @return mixed
     */
    public function getOrder($order_state= 4){
        $field = 'a.order_no,a.order_id,a.order_state,a.order_type,a.use_type,a.booking_type,a.order_time,a.car_type_id,a.area_id';
        $field.= ',b.from_addr departure,b.from_lon,b.from_lat,b.to_addr destination,b.to_lon,b.to_lat,b.plan_time,b.call_time';
        $field.= ',c.type,c.car_type,d.law_type,d.prop,a.reorder,a.pay_type';
        $where['order_state'] = $order_state;
        $time  = time() - 60*60*24;
        // $etime = time() + 180;
        try{$order = $this->alias('a')
            ->join('order_gps b','a.order_id = b.order_id','left')
            ->join('car_type c','a.car_type_id = c.car_type_id','left')
            ->join('company d','d.company_id = a.company_id')
            ->where($where)
            ->where('b.plan_time','> time',date('Y-m-d H:i:s',$time))
            ->whereNull('a.delete_time')
            ->field($field)
            ->select();
        }catch (Exception $e){
            // TODO 错误处理
            $order = [];
        }
        return $order;
    }
}